package com.weishe.loc;

import java.util.Date;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class LocMain {

	public static void main(String[] args) throws Exception {
		String inputPath = "hdfs://192.168.15.11:9000/data/pos.txt";
		String outputPath = "hdfs://192.168.15.11:9000/output/pos" + (new Date()).getTime();

		// 1、配置文件
		Configuration conf = new Configuration();
		//conf.set("mapred.jar", "/private/var/root/Desktop/hadoop.jar");
		Job job = Job.getInstance(conf);
		job.setJarByClass(LocMain.class);
		// 2、设置Job

		job.setJobName("top three LocMain");
		
		

		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(Loc.class);
		//
		// job.setInputFormatClass(KeyValueTextInputFormat.class);
		// 如果是mapper 和reduce的输出是一样的name就采用这个设置
		// job.setOutputKeyClass(FOF.class);
		// job.setOutputValueClass(IntWritable.class);

		job.setMapperClass(LocMapper.class);
		job.setReducerClass(LocReducer.class);

		// 设置reducer的数量
		// job.setNumReduceTasks(3);

		FileInputFormat.setInputPaths(job, new Path(inputPath));
		Path op = new Path(outputPath);
		// if (fs.exists(op)) {
		// fs.delete(op, true);
		// }
		FileOutputFormat.setOutputPath(job, op);

		boolean f = job.waitForCompletion(true);
		if (f) {
			System.out.println("job 成功执行");
		}
	}

}
